<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招聘ID" prop="recruitId">
        <el-input
          v-model="queryParams.recruitId"
          placeholder="请输入招聘ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="简历ID" prop="recruitCvId">
        <el-input
          v-model="queryParams.recruitCvId"
          placeholder="请输入简历ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地点" prop="place">
        <el-input
          v-model="queryParams.place"
          placeholder="请输入地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="面试时间" prop="time">
        <el-date-picker clearable
          v-model="queryParams.time"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择面试时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:interview:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:interview:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:interview:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:interview:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->


  

  <div style="height: 300px;">
      <el-row :gutter="12">
        <el-col :span="24">
          <el-card class="progress-card" shadow="hover" style="width: 100%;height: 300px;">
            <div id="interview_line"  style="width: 100%;height: 300px;"></div>
          </el-card>
        </el-col>
      </el-row>
    </div>


    <el-table v-loading="loading" :data="interviewList" @selection-change="handleSelectionChange"  :row-class-name="tableRowClassName" style="margin-top: 15px;">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="通知ID" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <!-- <el-table-column label="招聘ID" align="center" prop="recruitId" /> -->
      <el-table-column label="简历ID" align="center" prop="recruitCvId" />
      <el-table-column label="地点" align="center" prop="place" />
      <el-table-column label="面试时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注意事项" align="center" prop="tips" />
      <el-table-column label="面试状态" align="center" prop="progress">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_interview_progress" :value="scope.row.progress"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleFinish(scope.row)"
            v-hasPermi="['system:interview:edit']"
            v-if="scope.row.progress !== '1'"
          >完成面试</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:interview:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:interview:remove']"
          >取消</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改面试记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="招聘ID" prop="recruitId">
          <el-input v-model="form.recruitId" placeholder="请输入招聘ID" />
        </el-form-item>
        <el-form-item label="简历ID" prop="recruitCvId">
          <el-input v-model="form.recruitCvId" placeholder="请输入简历ID" />
        </el-form-item> -->
        <el-form-item label="地点" prop="place">
          <el-input v-model="form.place" placeholder="请输入地点" />
        </el-form-item>
        <el-form-item label="面试时间" prop="time">
          <el-date-picker clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择面试时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="注意事项" prop="tips">
          <el-input v-model="form.tips" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInterview, getInterview, delInterview, addInterview, updateInterview, getOneWeekInterviewNum } from "@/api/system/interview";
import * as echarts from 'echarts';

export default {
  name: "Interview",
  dicts: ['sys_interview_progress'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 面试记录表格数据
      interviewList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        recruitId: null,
        recruitCvId: null,
        place: null,
        time: null,
        tips: null,
        progress: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户ID不能为空", trigger: "blur" }
        ],
        recruitId: [
          { required: true, message: "招聘ID不能为空", trigger: "blur" }
        ],
        recruitCvId: [
          { required: true, message: "简历ID不能为空", trigger: "blur" }
        ],
        place: [
          { required: true, message: "地点不能为空", trigger: "blur" }
        ],
        time: [
          { required: true, message: "面试时间不能为空", trigger: "blur" }
        ],
      },
      //没有面试的数量
      noInterviewNum: 0,
      //已经面试过的数量
      interviewNum: 0
    };
  },
  mounted(){
    var lineDom = document.getElementById('interview_line');
    var line_Chart = echarts.init(lineDom);

  
    const line_option = {
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value',
        min: 0,
        splitNumber: 4
      },
      series: [
        {
          data: [],
          type: 'line',
        
        }
      ]
    };
    
    

    getOneWeekInterviewNum().then(res => {
      line_option.xAxis.data = res.data.map(item => item.date);
      line_option.series[0].data = res.data.map(item => item.count);
      line_Chart.setOption(line_option);
    })
  },
  created() {
    this.getList();
  },
  methods: {

    /** 查询面试记录列表 */
    getList() {
      this.loading = true;
      listInterview(this.queryParams).then(response => {
        this.interviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.getNum();
    },
    getNum(){
      for(let i = 0; i < this.interviewList.length; i++) {
          if(this.interviewList[i].progress == "0") {
              this.noInterviewNum++;
          } else {
              this.InterviewNum++;
          }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        recruitId: null,
        recruitCvId: null,
        place: null,
        time: null,
        tips: null,
        progress: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加面试记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInterview(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改面试记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInterview(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInterview(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除面试记录编号为"' + ids + '"的数据项？').then(function() {
        return delInterview(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleFinish(row){
      const id = row.id;
      this.$modal.confirm('是否已经面试完成编号为"' + id + '"的面试？').then(() => {
        getInterview(id).then(response => {
          this.form = response.data;
          this.form.progress = "1";
          updateInterview(this.form).then(response => {
            this.$modal.msgSuccess("通过成功");
            this.getList();
          });
        });
      }).catch(() => {
        // 处理取消操作
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/interview/export', {
        ...this.queryParams
      }, `interview_${new Date().getTime()}.xlsx`)
    },
    tableRowClassName({row, rowIndex}) {
        if (row.progress === "0") {
          return 'warning-row';
        } else if (row.progress === "1") {
          return 'success-row';
        }
        return '';
      }
  }
};
</script>


<style>
  .el-table .warning-row {
    background: rgb(254, 214, 203);
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>
